package com.atguigu.lease.web.app.listener;

import com.atguigu.lease.common.constant.RabbitConstant;
import com.atguigu.lease.web.app.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;

@Slf4j
@Component
@RabbitListener(queues = RabbitConstant.APP_SMS_QUEUE)
public class SMSQueuelistener {

    @Autowired
    private SmsService smsService;

    @RabbitHandler
    public void listen(Map<String, Object> map){
        log.info("收到短信队列消息:{}", map);
        String phone = (String) map.get("phone");
        String code = (String) map.get("code");
        smsService.sendSms(phone, code);
    }
}
